#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 2e5+10;
const int mod = 998244353;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
int n,m,q;
int pw[maxn];
int fa[maxn],dep[maxn];
ll dis[maxn];
vector<pii > G[maxn];
int st[maxn],ed[maxn],tot,id[maxn];
int tp[maxn],siz[maxn],son[maxn];
void dfs(int x,int ff) {
	st[x] = ++tot; id[tot] = x;
	fa[x] = ff; //for(int i = 1; i < 18 && fa[x][i-1]; i++) fa[x][i] = fa[fa[x][i-1]][i-1];
	siz[x] = 1; son[x] = 0;
	for(pii e : G[x]) if(e.fi != ff) {
		dep[e.fi] = dep[x] + 1; dis[e.fi] = dis[x] + e.se;
		dfs(e.fi,x);
		if(son[x] == 0 || siz[son[x]] < siz[e.fi]) son[x] = e.fi;
		siz[x] += siz[e.fi];
	}
	ed[x] = tot;
}
void dfs2(int x,int ttp) {
	tp[x] = ttp;
	if(son[x]) dfs2(son[x],ttp);
	for(pii e : G[x]) if(e.fi != fa[x] && e.fi != son[x]) {
		dfs2(e.fi,e.fi);
	}
}
int lca(int x,int y) {
	while(tp[x] != tp[y]) {
		if(dep[tp[x]] < dep[tp[y]]) y = fa[tp[y]];
		else x = fa[tp[x]];
	}
	return ((dep[x] < dep[y]) ? x : y);
}
int s[20][maxn];
int query(int l,int r) {
	int k = pw[r-l+1];
	return lca(s[k][l],s[k][r-(1<<k)+1]);
}
int num = 0;
namespace Seg {
	struct Node {
		int ls,rs,cnt;
	}t[maxn*20];
	int cnt;
	void add(int &p,int x,int L = 1,int R = n) {
		t[++cnt] = t[p]; p = cnt; t[p].cnt++;
		if(L == R) {
			return;
		}
		int mid = (L + R) >> 1;
		if(x <= mid) add(t[p].ls,x,L,mid);
		else add(t[p].rs,x,mid+1,R);
		return;
	}
	bool query(int x,int y,int l,int r,int L = 1,int R = n) {
		if(t[x].cnt == t[y].cnt) return false;
		if(l <= L && R <= r) {
			return t[x].cnt < t[y].cnt;
		}
		int mid = (L + R) >> 1;
		if(r <= mid) return query(t[x].ls,t[y].ls,l,r,L,mid);
		if(l > mid) return query(t[x].rs,t[y].rs,l,r,mid+1,R);
		return  (query(t[x].ls,t[y].ls,l,r,L,mid) || query(t[x].rs,t[y].rs,l,r,mid+1,R)) ;
	}
	int pre(int x,int y,int p,int L = 1,int R = n) {
		if(t[x].cnt == t[y].cnt) return -1;
		if(L == R) {
			return id[L];
		}
		int mid = (L + R) >> 1;
		if(p > mid) {
			int tmp =  pre(t[x].rs,t[y].rs,p,mid+1,R);
			if(tmp != -1) return tmp;
		}
		return pre(t[x].ls,t[y].ls,p,L,mid);
	}
	int suf(int x,int y,int p,int L = 1,int R = n) {
		if(t[x].cnt == t[y].cnt) return -1;
		if(L == R) {
			return id[L];
		}
		int mid = (L + R) >> 1;
		if(p <= mid) {
			int tmp = suf(t[x].ls,t[y].ls,p,L,mid);
			if(tmp != -1) return tmp;
		}
		return suf(t[x].rs,t[y].rs,p,mid+1,R);
	}
};
bool in(int x,int y) { // x in y
	return (st[y] <= st[x] && st[x] <= ed[y]);
}
int rt[maxn];
void Solve() {
	cin >> n >> q;
	for(int i = 2; i <= n; i++) pw[i] = pw[i/2] + 1;
	for(int i = 1,u,v,w; i < n; i++) {
		cin >> u >> v >> w;
		G[u].pb(MP(v,w)); G[v].pb(MP(u,w));
	}
	dfs(1,0); dfs2(1,1);
	for(int i = 1; i <= n; i++) {
		s[0][i] = i;
	}
	for(int j = 1; (1<<j) <= n; j++) {
		for(int i = 1; i+(1<<j)-1 <= n; i++) {
//			cerr<<i<<' '<<j<<'\n';
			s[j][i] = lca(s[j-1][i],s[j-1][i+(1<<(j-1))]);
		}
	}
	for(int i = 1; i <= n; i++) {
		rt[i] = rt[i-1];
		Seg::add(rt[i],st[i]);
	}
	ll lst = 0;
	for(ll i = 1,l,r,p; i <= q; i++) {
		cin >> p >> l >> r;
		l ^= lst; r ^= lst; p ^= lst;
//		cerr<<i<<' '<<p<<' '<<l<<' '<<r<<'\n';
		int L = query(l,r);
		if(!in(p,L)) {
			lst = dis[p]+dis[L]-2*dis[lca(p,L)];
		} else if(Seg::query(rt[l-1],rt[r],st[p],ed[p])) {
			lst = 0;
		} else {
			int pre = Seg::pre(rt[l-1],rt[r],st[p]); if(pre == -1) pre = 1; else pre = lca(pre,p);
			int suf = Seg::suf(rt[l-1],rt[r],ed[p]); if(suf == -1) suf = 1; else suf = lca(suf,p);
			lst = dis[p]-max(dis[pre],dis[suf]);
//			cerr<<l<<' '<<r<<' '<<L<<' '<<p<<' '<<pre<<' '<<suf<<' '<<Seg::suf(rt[l-1],rt[r],ed[p])<<'\n';
		}
		cout<<lst<<'\n';
	}
//	cerr<<num<<'\n';
//	exit(0);
}
int main() {
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	int T; cin >> T; while(T--)
	Solve();
	return 0;
}
